// pages/index/index.js
import {baseUrl} from './../../util/util.js'
Page({
  data: {
    list: [],
    page: 0,
    isLoading: false
  },
  onLoad: function (options) {
    this.loadData()
  },
  loadData: function() {
    let { page, list } = this.data
    wx.showLoading({
      title: '正在拼命加载中...',
      mask: true
    })
    this.setData({
      isLoading: true
    })
    wx.request({
      url: `${baseUrl}h5-view/v/movie/list/?page_start=${this.data.page}`,
      success: res => {
        page += 10
        list.push(...res.data.subjects)
        this.setData({
          list: list,
          page,
          isLoading: false
        })
        wx.hideLoading()
      }
    })
  },
  scrollToLower: function () {
    if(!this.data.isLoading){
      this.loadData()
    }
  },
  goToDetail: function(e){
    wx.navigateTo({
      url: `/pages/detail/detail?id=${e.currentTarget.dataset.id}`,
    })
  }
})